//
//  ViewController.m
//  shareSDK_SMS_Test
//
//  Created by terrylee on 4/25/16.
//  Copyright © 2016 terry. All rights reserved.
//

#import "ViewController.h"
#import <SMS_SDK/SMSSDK.h>

@interface ViewController ()

@property(nonatomic,strong)UITextField *verifyCodeField;


@end

@implementation ViewController

-(UITextField *)verifyCodeField{
    if (_verifyCodeField == nil) {
        _verifyCodeField = [[UITextField alloc]init];
    }
    return _verifyCodeField;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    
    [btn setTitle:@"短信验证" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor greenColor]];
    
    [btn addTarget:self action:@selector(SMS) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
    
    self.verifyCodeField.frame = CGRectMake(0, 100, 100, 100);
    self.verifyCodeField.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.verifyCodeField];
    
    
    UIButton *commit_Btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 200, 100, 100)];
    
    [commit_Btn setTitle:@"提交" forState:UIControlStateNormal];
    [commit_Btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [commit_Btn setBackgroundColor:[UIColor greenColor]];
    
    [commit_Btn addTarget:self action:@selector(commit) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:commit_Btn];
    
}

-(void)SMS{
    
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:@"18511989746" zone:@"86" customIdentifier:nil result:^(NSError *error) {
        if (!error) {
            NSLog(@"获取验证码成功");
        }else{
            NSLog(@"错误信息:%@",error);
        }
    }];
    
    
    
    
    
}
-(void)commit{
    
    [SMSSDK commitVerificationCode:self.verifyCodeField.text phoneNumber:@"18511989746" zone:@"86" result:^(NSError *error) {
        
        if (!error) {
            NSLog(@"验证成功");
        }
        else
        {
            NSLog(@"错误信息:%@",error);
        }
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
